# 需求：读取接口返回响应对象中html信息
from bs4 import BeautifulSoup


# 定义函数
def parser_html(response):
    #     html = """<form name='easypaysubmit' id='easypaysubmit' target='_blank'
    # method='post' action='http://mertest.chinapnr.com/muser/publicRequests'><input
    # name='Version' type='hidden' value='10'/><input name='CmdId' type='hidden'
    # value='UserRegister'/><input name='MerCustId' type='hidden'
    # value='6000060007313892'/></form>"""
    # 实例化bs对象
    html = response.json().get("description").get("form")  # ***
    bs = BeautifulSoup(markup=html, features="html.parser")
    # 调用方法获取html信息：url、input标签中的name属性值
    url = bs.form.get("action")
    # name属性值和value属性值
    data = bs.find_all("input")
    # 定义空字典，存放name属性值和value属性值
    data_dict = {}
    # 循环遍历获取每个标签元素
    for i in data:  # ***
        # print(i)
        key = i.get("name")
        value = i.get("value")
        data_dict[key] = value
    # 返回提取结果
    return url, data_dict


if __name__ == '__main__':
    pass
    # res = parser_html(aaa)
    # print(res,type(res))
